﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using DataAccess;
using Com.Alipay;

namespace AnTeWei.Dao
{
    public class VaildationDao
    {
        //验证用户是否存在
        public static string CheckLoginId(string strLoginId)
        {
            string strSql = "";
            string strResult = "";

            strLoginId = strLoginId.Split('|')[1].ToString();


            Log.Debug("CheckLoginId", strLoginId);
            strSql = @"select count(*) count from T_AppUser where tauLoginId='{0}'";

            strSql = string.Format(strSql, strLoginId);

            DataTable dtResult = new DALTransaction().GetDataTableBySQLText(strSql);

            strResult = dtResult.Rows[0]["count"].ToString();

            return strResult;
        }

        //验证用户是否存在(不传区号)
        public static string CheckLogin(string strLoginId)
        {
            string strSql = "";
            string strResult = "";

            strSql = @"select count(*) count from T_AppUser where tauLoginId='{0}'";

            strSql = string.Format(strSql, strLoginId);

            DataTable dtResult = new DALTransaction().GetDataTableBySQLText(strSql);

            strResult = dtResult.Rows[0]["count"].ToString();

            return strResult;
        }

        //验证邀请码是否存在
        public static void SelectCodeInfo(string strCode, ref DataTable dtSCode, ref DataTable dtAUser)
        {
            string strSql = "";


            strSql = @"select * from T_SupplyCode where Code='{0}' and IsUsed='0'";
            strSql = string.Format(strSql, strCode);
            dtSCode= new DALTransaction().GetDataTableBySQLText(strSql);


            strSql = "";
            strSql = @"select * from T_AppUser where tauAdditional1='{0}' and tauType in (4,5)";
            strSql = string.Format(strSql, strCode);
            dtAUser = new DALTransaction().GetDataTableBySQLText(strSql);
        }

        //验证是否查过截止日期
        public static bool CheckDiffTime(string strTdiId)
        {
            int intDiff = 0;
            string strSql = @"select datediff(second,GETDATE(), t1.tdiBIdEndTime) diffSecond
	                        from T_DemandInformation t1  
                            where t1.tdiNo='{0}'";
            strSql=string.Format(strSql, strTdiId);
            
            DataTable dt = new DALTransaction().GetDataTableBySQLText(strSql);

            if (dt == null || dt.Rows.Count == 0)
                return false;

            intDiff = Convert.ToInt32(dt.Rows[0]["diffSecond"].ToString());
            
            if (intDiff <= 0)
            {
                string strSql1 = "update T_DemandInformation set tdiRowStatus=3 where tdiNo='{0}'";
                strSql1 = string.Format(strSql1, strTdiId);
                new DALTransaction().ExecuteQuerySQLText(strSql1);

                return false;
            }
            else
            {
                return true;
            }

        }
    }
}